import WebView from 'react-native-webview';
import { ScrollView, StatusBar, View, Button, Text, TextInput } from 'react-native';
import { TestCase, Tester,TestSuite } from '@rnoh/testerino';
import React, { useRef, useState, useCallback } from 'react';

export default function WebViewTestonShouldStartLoadWithRequest() {
  const [uri, seturi] = useState('https://www.baidu.com/')
  const onShouldStartLoadWithRequest = useCallback(
     (event: any) => {
      console.log('test event', event)
      return event.url===('https://www.baidu.com')
    },
    [],)


  return (
    <View style={{ flex:1}}>
        <Tester style={{ paddingBottom: 80 }}>
        <TestSuite name="react-native-webview">
            <TestCase
            key={'webview api onShouldStartLoadWithRequest'}
            itShould={`webview api onShouldStartLoadWithRequest`}
            tags={['C_API']}
            initialState={false}
            arrange={({ setState }) => {
              return (
                <View style={{ padding: 20, height: 500 }}>
                  <Text> onShouldStartLoadWithRequest</Text>
                  <WebView
                    source={{ uri: "https://developer.huawei.com" }}
                    onShouldStartLoadWithRequest={onShouldStartLoadWithRequest}
                     />
                </View>
              );
            }}
            assert={async ({ expect, state }) => {
              expect(state).to.be.true;
            }}
          />
          </TestSuite>
        </Tester>
    </View>
  );
}
